package com.lxl.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.lxl.model.User;
import com.lxl.service.UserService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 用户_搜索用户Action
 * 
 * @author 刘星鹭 
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2015年7月25日 上午9:12:49
 */
@Controller
@Transactional
public class SearchUserAction {

    @Resource
    UserService userService;// 注入用户Service
    
    private int fieldType;//要搜索的值的类别
    
    private String value;//要搜索的值
    
    private List<User> userList;// 用户列表
    
    private int pageNow = 1;// 当前页数
    private int pageCount = 0;// 总页数
    
    public String execute(){        
        userList=new ArrayList<User>();
        ActionContext context = ActionContext.getContext();// 获取action上下文
        HttpServletRequest request = (HttpServletRequest) context
                .get(ServletActionContext.HTTP_REQUEST);
        pageCount = userService.pageCount();
        request.setAttribute("pageCount", pageCount);
        request.setAttribute("pageNow", pageNow);
        if(value==null){
            userList = userService.listTen(pageNow);
            return "success";
        }
        userList.add(userService.find(value));
        return "success";
    }

    public int getFieldType() {
        return fieldType;
    }

    public void setFieldType(int fieldType) {
        this.fieldType = fieldType;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }    
    
    
    
}
